package tw.com.hitevision.whiteboard.android.stateFile;

import android.animation.ValueAnimator;
import android.content.Context;
import android.util.AttributeSet;

import androidx.constraintlayout.widget.ConstraintLayout;
import tw.com.hitevision.whiteboard.android.R;

public class JsonLoadBlockingVIew extends ConstraintLayout {
    private static final String TAG = JsonLoadBlockingVIew.class.getSimpleName();
    private static final String LOADING_TEXT = "Loading";
    private static final String LOADING_TEXT_DOT = "Loading.";
    private static final String LOADING_TEXT_DOT_DOT = "Loading..";
    private static final String LOADING_TEXT_DOT_DOT_DOT = "Loading...";

    private ValueAnimator valueAnimator;
//    private TextView loadingText;

    public JsonLoadBlockingVIew(Context context) {
        super(context);
        init(context);
    }

    public JsonLoadBlockingVIew(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        init(context);
    }

    public JsonLoadBlockingVIew(Context context, AttributeSet attributeSet, int def) {
        super(context, attributeSet, def);
        init(context);
    }

    private void init(Context context) {
        inflate(context, R.layout.json_load_blocking_view_layout, this);

//        loadingText = findViewById(R.id.loading_text);

        this.setOnTouchListener((v, event) -> true);
    }

//    private static ValueAnimator createDotAnimation(TextView loadingText) {
//        ValueAnimator valueAnimator = new ValueAnimator().ofInt(0, 4);
//        valueAnimator.setDuration(4000);
//        valueAnimator.setRepeatMode(ValueAnimator.RESTART);
//        valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
//
//        valueAnimator.addUpdateListener(animation -> {
//            if (((int) animation.getAnimatedValue()) == 0) {
//                loadingText.setText(LOADING_TEXT);
//            } else if (((int) animation.getAnimatedValue()) == 1) {
//                loadingText.setText(LOADING_TEXT_DOT);
//            } else if (((int) animation.getAnimatedValue()) == 2) {
//                loadingText.setText(LOADING_TEXT_DOT_DOT);
//            } else if (((int) animation.getAnimatedValue()) == 3) {
//                loadingText.setText(LOADING_TEXT_DOT_DOT_DOT);
//            }
//        });
//
//        valueAnimator.start();
//
//        return valueAnimator;
//    }

//    @Override
//    public void setVisibility(int visibility) {
//        super.setVisibility(visibility);
//
//        if (visibility == VISIBLE) {
//            valueAnimator = createDotAnimation(loadingText);
//        } else {
//            if (valueAnimator != null) {
//                valueAnimator.cancel();
//            }
//        }
//
//    }

}
